package com.hmsproject.db.expediadb;

import java.math.BigInteger;
import java.security.MessageDigest;

public class HMSExpediaDBConstants {
	
	private static HMSExpediaDBConstants hmsExpediaDBConstants = new HMSExpediaDBConstants();
	
	private char urlSlash = '/';
	private char ambers = '&';
	
	public char getAmbers() {
		return ambers;
	}

	private MessageDigest md;
	
	private String sig;
	
	private HMSExpediaDBConstants(){
		
		try{
			md = MessageDigest.getInstance("MD5");
		}catch(Exception e){
			throw new RuntimeException(e.getMessage());
		}
	}
	
	public static HMSExpediaDBConstants getInstance(){
		return hmsExpediaDBConstants;
	}
	
	public String getBaseService(){
		return baseService;
	}
	
	private String baseService = "http://dev.api.ean.com/ean-services/rs/hotel/v3/";
	private String apiKey = "xt5fd6vhdbfqb7gqexkqdjk6";
	private String minorRev="28";
	
	public String getMinorRev() {
		return minorRev;
	}

	public String getSecret() {
		return secret;
	}

	public String getCid() {
		return cid;
	}

	private String secret = "EEDrASKU";
	private String cid = "55505";

	public String getApiKey() {
		return apiKey;
	}
	
	public String getSig() throws Exception{
		
		long timeInSeconds = (System.currentTimeMillis() / 1000);
		String input = getApiKey() + getSecret() + timeInSeconds;
		md.update(input.getBytes());
		
		return String.format("%032x", new BigInteger(1, md.digest()));
	}

	public String getBaseUrl(String method) throws Exception{
		return getBaseService() + method + '?' + "apikey=" + getApiKey() + getAmbers() + "sig=" + getSig() + getAmbers() + "minorRev=" + getMinorRev() + 
					getAmbers() + "cid=" + getCid();
	}


}
